package base;

/**
 * instanceof是Java的保留关键字,左边是对象,右边是类;
 * 当对象是右边类或子类所创建对象时,返回true;否则返回false
 *
 * @author 王霄
 * @date 2021/9/16 22:01
 */
public class InstanceofDemo {
    public static void main(String[] args) {
        A a = new A();
        System.out.println(a instanceof A);
        System.out.println(a instanceof B);
        System.out.println(a instanceof C);
        System.out.println(a instanceof Object);
        System.out.println("============================");
        B b = new A();
        System.out.println(b instanceof A);
        System.out.println(b instanceof B);
        System.out.println(b instanceof C);
        System.out.println(b instanceof Object);
        System.out.println("============================");
        B b_ = new B();
        System.out.println(b_ instanceof A);
        System.out.println(b_ instanceof B);
        System.out.println(b_ instanceof C);
        System.out.println(b_ instanceof Object);
    }

    public static class A extends B implements C {

    }

    public static class B {

    }

    public interface C {

    }
}
